package com.shuwang.goods.until;

import java.util.Date;
import java.util.Random;

public class IDBuilder {
	/**
	 * @description ID编号 生成
	 * @return
	 */
	public final static Long SNShortWithMirocSec(Integer first,Integer len) {
		// 获取当前系统时间
		String time = String.valueOf(System.currentTimeMillis());
		return Long.parseLong(time.substring(first, len));
	}

	public final static long SNLongWithMirocSec() {
		// 获取当前系统时间
		String time = String.valueOf(System.currentTimeMillis());
		return Long.parseLong(time);
	}

	public final static String SNString() {
		// 获取当前系统时间
		String time = String.valueOf(System.currentTimeMillis());
		Random random = new Random();
		int randomnum = random.nextInt();
		if (randomnum < 0) {
			randomnum = randomnum * (-1);
		}
		return time + randomnum;
	}

	public final static String getRandomNumber(String type,Integer length) {
		String val = "";
		Random random = new Random();
		for (int j = 0; j < length; j++) {
			if("mdae".equals(type)){
				String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
				if ("char".equalsIgnoreCase(charOrNum)) {
					int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
					val += (char) (random.nextInt(26) + temp);
				} else if ("num".equalsIgnoreCase(charOrNum)) {
					val += String.valueOf(random.nextInt(10));
				}
			}else if( "digital".equals(type)){
				val += String.valueOf(random.nextInt(10));
			}

		}
		return val;
	}

	// 设置某个类型中的ID
	public final static Long CreateAnyId(String anyValue){

		Date craateId = new Date();

		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(anyValue).append(craateId.getTime());
		return Long.parseLong(stringBuilder.toString());
	}
}
